<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    // console.log(random)

    let random = Math.round(Math.random() * 9) + 1
    let i = 0
    while (true) {
      let user = prompt('请输入一个数字')
      i++
      if (i >= 8) {
        break
      }
      if (random < user) {
        alert('猜大了')
      } else if (random > user) {
        alert('猜小了')
      } else {
        alert('猜对了')
        break
      }

    }
  </script>
</body>

</html>